home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / program_perfection / toolbar_demo / toolbar_demo.c < prev    next >
C/C++ Source or Header  |  2000-02-16  |  6KB  |  228 lines

  1. /*
  2.  * A quick demo for Reaction SpeedBar class
  3.  * Richard Drummond 3/2/2000
  4.  *
  5.  */
  6.  
  7. #include <exec/types.h>
  8. #include <intuition/intuition.h>
  9.  
  10. #include <proto/intuition.h>
  11. #include <proto/exec.h>
  12. #include <proto/dos.h>
  13.  
  14. #define ALL_REACTION_CLASSES
  15. #define ALL_REACTION_MACROS
  16. #include <reaction/reaction.h>
  17.  
  18.  
  19. #define GID_QUIT  1L
  20.  
  21.  
  22. struct SpeedButton
  23. {
  24.     UBYTE           ID;
  25.     BOOL            Disabled;
  26.     CONST_STRPTR    ImageName;
  27. };
  28.  
  29. enum
  30. {
  31.     SBID_OPEN_BUTTON,
  32.     SBID_COPY_BUTTON,
  33.     SBID_SEARCH_BUTTON,
  34.     SBID_GOTO_BUTTON
  35. };
  36.  
  37.  
  38. CONST struct SpeedButton ButtonData[] = {
  39.     { SBID_OPEN_BUTTON,   FALSE, "PROGDIR:load.ilbm"  },
  40.     { SBID_COPY_BUTTON,   TRUE,  "PROGDIR:copy.ilbm"   },
  41.     { SBID_SEARCH_BUTTON, FALSE, "PROGDIR:search.ilbm" },
  42.     { SBID_GOTO_BUTTON,   FALSE, "PROGDIR:goto.ilbm"   },
  43.     { 0, FALSE, NULL }
  44. };
  45.  
  46.  
  47.  
  48. /*
  49.  * CreateButtons()
  50.  *
  51.  * Allocate the buttons for our speed bar
  52.  */
  53.  
  54. BOOL
  55. CreateButtons( struct SpeedButton *button, struct List *list, struct Screen *screen )
  56. {
  57.  
  58. /*    struct SpeedButton *button; */
  59.  
  60.     NewList( list );
  61.  
  62.     for( /* button = &(ButtonData[0]) */ ; button->ImageName; button++ )
  63.     {
  64.         struct Object *image;
  65.  
  66.         if( image = BitMapObject,
  67.                             BITMAP_SourceFile, button->ImageName,
  68.                             BITMAP_Screen,     screen,
  69.                         BitMapEnd )
  70.         {
  71.             struct Node *node;
  72.  
  73.             if( node = AllocSpeedButtonNode( (BYTE) -button->ID,
  74.                                                 SBNA_Image,     image,
  75.                                                 SBNA_Disabled,  button->Disabled,
  76.                                                 SBNA_Spacing,   -1,
  77.                                                 SBNA_Highlight, SBH_RECESS,
  78.                                             TAG_DONE ) )
  79.             {
  80.                 /* Okay - now add it to speedbar list */
  81.                 Enqueue( list, node );
  82.  
  83.             }
  84.         }
  85.     } /* for */
  86.  
  87.     /* We really need some cleanup here */
  88.     return TRUE;
  89. }
  90.  
  91.  
  92.  
  93. /*
  94.  * FreeButtons()
  95.  *
  96.  * Deallocate our speedbar buttons
  97.  */
  98.  
  99. VOID
  100. FreeButtons( struct List *list )
  101. {
  102.     struct Node *node, *next;
  103.  
  104.     /* get first in list */
  105.     node = list->lh_Head;
  106.  
  107.     while( next = node->ln_Succ )
  108.     {
  109.         Object *image;
  110.  
  111.         /* get a pointer to this object's image */
  112.         GetSpeedButtonNodeAttrs( node, SBNA_Image, &image, TAG_DONE );
  113.  
  114.         /* free it */
  115.         if(image)
  116.             DisposeObject(image);
  117.  
  118.         /* free the button itself */
  119.         FreeSpeedButtonNode( node );
  120.  
  121.         node = next;
  122.     }
  123.  
  124.     NewList( list );
  125. }
  126.  
  127.  
  128.  
  129.  
  130.  
  131. int main(void)
  132. {
  133.     struct Screen *screen;
  134.     struct List    speedbar_list;
  135.     Object        *win_obj;
  136.     
  137.     /* intialize */
  138.     screen = LockPubScreen( NULL );
  139.     CreateButtons( &ButtonData[0], &speedbar_list, screen );
  140.  
  141.     /* make the window object */
  142.     if( win_obj = WindowObject,
  143.                         WA_Title, "Speedbar Demo",
  144.                         WA_Activate, TRUE,
  145.                         WA_DepthGadget, TRUE,
  146.                         WA_DragBar, TRUE,
  147.                         WA_CloseGadget, TRUE,
  148.                         WA_SizeGadget, TRUE,
  149.                         WA_SizeBBottom, TRUE,
  150.                         WINDOW_Position, WPOS_CENTERMOUSE,
  151.                         WINDOW_ParentGroup, VGroupObject,
  152.                             LAYOUT_SpaceOuter, TRUE,
  153.                             LAYOUT_DeferLayout, TRUE,
  154.  
  155.                             /* Speedbar */
  156.                             LAYOUT_AddChild, SpeedBarObject,
  157.                                 SPEEDBAR_Orientation, SBORIENT_HORIZ,
  158.                                 SPEEDBAR_Buttons, &speedbar_list,
  159.                                 SPEEDBAR_BevelStyle, BVS_NONE,
  160.                             SpeedBarEnd,
  161.                             CHILD_NominalSize,TRUE,
  162.  
  163.                             /* Quit button */
  164.                             LAYOUT_AddChild, ButtonObject,
  165.                                 GA_ID, GID_QUIT,
  166.                                 GA_RelVerify, TRUE,
  167.                                 GA_Text,"_Quit",
  168.                             ButtonEnd,
  169.                             CHILD_WeightedHeight, 0,
  170.                         EndGroup,
  171.                      EndWindow )
  172.     {
  173.         struct Window *window;      /* the actual Intuition window */
  174.  
  175.         if( window = (struct Window *) RA_OpenWindow( win_obj ) )
  176.         {
  177.             ULONG wait, signal;
  178.             ULONG done = FALSE;
  179.             ULONG result;
  180.             UWORD code;
  181.  
  182.                     /* Get the window's signal bit */
  183.                     GetAttr( WINDOW_SigMask, win_obj, &signal );
  184.  
  185.                     /* Even loop */
  186.                     while( !done )
  187.                     {
  188.                         wait = Wait( signal | SIGBREAKF_CTRL_C );
  189.  
  190.                         if ( wait & SIGBREAKF_CTRL_C )
  191.                         {
  192.                             done = TRUE;
  193.                         }
  194.                         else
  195.                         {
  196.                             while( ( result = RA_HandleInput( win_obj, &code ) ) != WMHI_LASTMSG )
  197.                             {
  198.                                 switch( result & WMHI_CLASSMASK )
  199.                                 {
  200.                                     case WMHI_CLOSEWINDOW:
  201.                                         done = TRUE;
  202.                                         break;
  203.  
  204.                                     case WMHI_GADGETUP:
  205.                                         switch (result & WMHI_GADGETMASK)
  206.                                         {
  207.                                             case GID_QUIT:
  208.                                                 done = TRUE;
  209.                                                 break;
  210.                                         }
  211.                                         break;
  212.                                 }
  213.                             }
  214.                         } /* else */
  215.                     } /* end event loop  */
  216.  
  217.         } /* end if */
  218.  
  219.         DisposeObject( win_obj );
  220.     }
  221.  
  222.     /* Cleanup */
  223.     FreeButtons( &speedbar_list );
  224.     UnlockPubScreen( NULL, screen );
  225.  
  226.     return 0L;
  227. }
  228.